#pragma once

#include "DLL.h"
#include <MyViews/Tool.h>
#include "Bezier.h"
#include "ConvertTool.h"
#include "AddPointTool.h"

namespace My {

class BezierEditor;

class DLL_API DrawTool : public Tool
{
	enum ToolMode {
		tmDraw,
		tmConvert,
		tmAddPoint
	};
public:
	DrawTool(BezierEditor & owner);
public:
	virtual void PaintRect(CDC * pDC, const CRect & r);
	virtual void OnLButtonDown(UINT nFlags, CPoint p);
	virtual void OnLButtonDblClk(UINT nFlags, CPoint p);
	virtual void OnLButtonUp(UINT nFlags, CPoint p);
	virtual void OnRButtonDown(UINT nFlags, CPoint p);
	virtual void OnRButtonDblClk(UINT nFlags, CPoint p);
	virtual void OnRButtonUp(UINT nFlags, CPoint p);
	virtual void OnMouseMove(UINT nFlags, CPoint p);
	virtual void OnMouseEnter(UINT nFlags, CPoint p);
	virtual void OnMouseLeave();
	virtual void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	virtual void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	virtual bool OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
private:
	// Returns pointer to a curve that can be extended by drawing;
	// dir == 0 means a node can be added at the beginning, otherwise dir == 1
	Bezier * GetActiveCurve(Size & dir) const;
private:
	BezierEditor &	m_Owner;
	ConvertTool		m_Convert;
	AddPointTool	m_AddPoint;
	ToolMode		m_Mode;
};

} //namespace My
